/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ui;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/**
 *
 * @author kien.tran
 */
public abstract class AListItem extends AItem {

    protected String text;
    protected Image icon;
    protected String[] textRows = null;
    protected Style style;

    public AListItem(String text, Image icon) {
        this.text = text;
        this.icon = icon;
    }

    public AListItem(String id, int x, int y, int width, int height, boolean focus, boolean visible, String text, Image icon) {
        super(id, x, y, width, height, focus, visible);
        this.text = text;
        this.icon = icon;
    }

    public Image getIcon() {
        return icon;
    }

    public void setIcon(Image icon) {
        this.icon = icon;
    }

    public String getText() {
        return text;
    }

    public int getHeight() {
        calculateHeight();
        return this.height;
    }

    public void setParent(ACanvas parent) {
        super.setParent(parent);
        if (parent != null) {
            this.style = parent.getStyle().getItemStyle();
        }
    }

    protected abstract void calculateHeight();

    public void setText(String text) {
        this.text = text;
        //setTextRows(text);
    }

    protected abstract void setTextRows(String title);

    public abstract void paint(int x, int y, Graphics g);

    public boolean isPaint(int x, int y) {
        if (!visible) {
            return true;
        }
        calculateHeight();
        int itemX = parent.getItemX(), itemY = parent.getItemY(), parentW = parent.getWidth(), parentH = parent.getHeight() - parent.getFooterHeight();
        if (x < itemX || x > parentW) {
            return false;
        }

        if (y + height < itemY || y > parentH) {
            return false;
        }

        return true;
    }

    public boolean isSelectedPaint(int x, int y) {
        if (!visible) {
            return true;
        }
        calculateHeight();
        int itemX = parent.getItemX(), itemY = parent.getItemY(), parentW = parent.getWidth(), parentH = parent.getHeight() - parent.getFooterHeight();
        if (x < itemX || x + width > parentW) {
            return false;
        }

        if (y < itemY || y + height > parentH) {
            return false;
        }

        return true;
    }
}
